<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>成果分类 | {$system_name}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="{_ADMIN_STATIC_}/i/favicon.png">
    <!-- <link rel="apple-touch-icon-precomposed" href="{_ADMIN_STATIC_}/i/app-icon72x72@2x.png"> -->
    <link rel="stylesheet" href="{_ADMIN_STATIC_}/css/amazeui.min.css" />
    <link rel="stylesheet" href="{_ADMIN_STATIC_}/css/admin.css">
    <link rel="stylesheet" href="{_ADMIN_STATIC_}/css/app.css">
    <!-- <script src="{_ADMIN_STATIC_}/js/echarts.min.js"></script> -->

</head>

<body data-type="index">
    <!-- 头部导航栏 -->
    {include file='public/header'}
    <!-- 左侧侧边栏 -->
    {include file='public/side'}
    <!-- 中间内容开始 -->

    <!-- 标题 -->
    <div class="tpl-content-page-title">
        {$system_name} -- 成果分类
    </div>
    <!-- 面包屑导航 -->
    <ol class="am-breadcrumb">
        <li><a href="{$index_home}" class="am-icon-home">成果管理首页</a></li>
        <li>成果分类</li>
    </ol>
    <!-- 提示信息 -->
    <div class="tpl-content-scope">
        <div class="note note-info">
            <h3> 成果分类
                <span class="close" data-close="note"></span>
            </h3>
            <p>成果分类</p>
            <p><span class="label label-danger">提示:</span>
            </p>
        </div>

        <div class="tpl-portlet-components">

            <div class="am-btn-group am-btn-group-xs">
                <button type="button" class="am-btn am-btn-default am-btn-success" onclick="classify_add()"><span
                        class="am-icon-plus"></span>
                    新增</button>
            </div>

            <!-- 内容 -->
            <table class="am-table am-table-striped am-table-hover table-main">
                <thead>
                    <tr>
                        <th class="table-id">#</th>
                        <th class="table-title" style="width: 100px;">类别名称</th>
                        <th class="table-type" style="width: 200px;">类别描述</th>
                        <th class="table-author am-hide-sm-only">创建日期</th>
                        <th class="table-title" style="width: 80px;">是否启用</th>
                        <th class="table-date am-hide-sm-only">创建者</th>
                        <th class="table-set">操作</th>
                    </tr>
                </thead>
                <tbody>

                    {volist name="am_list" id="row" empty="$empty"}
                    <tr>
                        <td>{$row.id}</td>
                        <td>{$row.name}</td>
                        <td>{$row.note}</td>
                        <td class="am-hide-sm-only">{$row.create_time | date='Y-m-d H:i'}</td>
                        <td class="tpl-switch">
                            <input id="issue_checkbox_{$row.id}" type="checkbox" style="width: 50px;height: 28px;"
                                class="ios-switch bigswitch tpl-switch-btn" am_issue="{$row.issue}"
                                onclick="classify_issue('{$row.id}')" {$row.issue==1 ? 'checked' : '' }>
                            <div class="tpl-switch-btn-view">
                                <div>
                                </div>
                            </div>
                        </td>
                        <td class="am-hide-sm-only">{$row.admin_name}</td>
                        <td>
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                        onclick="classify_edit('{$row.id}')"><span
                                            class="am-icon-pencil-square-o"></span> 编辑</button>
                                    {if condition="$row.flag == 1"}
                                    <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                        onclick="classify_clear('{$row.id}')"><span class="am-icon-repeat"></span>
                                        清空</button>
                                    {/if}
                                    <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                        onclick="classify_del('{$row.id}')"><span class="am-icon-trash-o"></span>
                                        删除</button>
                                </div>
                            </div>
                        </td>
                    </tr>
                    {/volist}

                </tbody>
            </table>
            <!-- 加载分页组件 -->
            {include file="public/page"}
        </div>
    </div>


    <!-- 中间内容结束 -->
    <!-- 底部 -->
    <!-- {include file="public/footer"} -->

    <script src="{_ADMIN_STATIC_}/lib/jquery/jquery.js"></script>
    <script src="{_ADMIN_STATIC_}/js/amazeui.min.js"></script>
    <script src="{_ADMIN_STATIC_}/js/app.js"></script>
    <script src="{_ADMIN_STATIC_}/lib/layer/layer.js"></script>
    <script>

        // 添加一个分类
        function classify_add() {
            return layer.open({
                type: 2,
                title: '添加一个分类',
                skin: 'layui-layer-rim', //加上边框
                area: ['420px', '380px'], //宽高
                content: "{:url('AchievementManage/classify_add')}",
                end: function (e) {
                    location.reload();
                }
            });
        }

        // 启用禁用分类
        function classify_issue(id) {
            var issue_checkbox = $("#issue_checkbox_" + id);
            var issue_status = issue_checkbox.attr('am_issue');

            issue_status = (issue_status == 0) ? 1 : 0;

            $.ajax({
                url: "{:url('AchievementManage/classify_issue')}",
                data: {
                    'id': id,
                    'issue': issue_status,
                },
                type: "POST",
                dataType: "JSON",
                success: function (res) {
                    // 返回结果处理
                    if (res.code == 0) {
                        issue_checkbox.attr('am_issue', issue_status);
                        return layer.msg(res.msg, { icon: 1, time: 900 });
                    } else {
                        return layer.msg(res.msg, { icon: 2, time: 900 });
                    }
                }
            });
        }

        // 删除分类
        function classify_del(id) {
            layer.prompt({ title: '如果要删除该分类，请输入[立即删除]', formType: 0 }, function (text, index) {
                layer.close(index);
                if (text != "立即删除") {
                    return layer.msg('口令输入错误，无法删除', { icon: 2, time: 1500 });
                }

                $.ajax({
                    url: "{:url('AchievementManage/classify_del')}",
                    data: {
                        'id': id,
                        'text': text
                    },
                    type: "POST",
                    dataType: "JSON",
                    success: function (res) {
                        // 返回结果处理
                        if (res.code == 0) {
                            return layer.msg(res.msg, { icon: 1, time: 900 }, function () {
                                location.reload();
                            });
                        } else {
                            return layer.msg(res.msg, { icon: 2, time: 900 });
                        }
                    }
                });
            });
        }


        // 清除分类数据
        function classify_clear(cid) {
            layer.prompt({ title: '如果要清空该分类数据，请输入[立即清空]', formType: 0 }, function (text, index) {
                layer.close(index);
                if (text != "立即清空") {
                    return layer.msg('口令输入错误，无法清空', { icon: 2, time: 1500 });
                }

                $.ajax({
                    url: "{:url('AchievementManage/classify_clear')}",
                    data: {
                        'cid': cid,
                        'text': text
                    },
                    type: "POST",
                    dataType: "JSON",
                    success: function (res) {
                        // 返回结果处理
                        if (res.code == 0) {
                            return layer.msg(res.msg, { icon: 1, time: 900 }, function () {
                                location.reload();
                            });
                        } else {
                            return layer.msg(res.msg, { icon: 2, time: 900 });
                        }
                    }
                });
            });
        }


        // 编辑分类
        function classify_edit(id) {
            redirect_url('{$classify_edit}?id=' + id)
        }

        // 重定向
        function redirect_url(url) {
            window.location.href = url;
        }

    </script>
</body>

</html>